﻿using MediatR;
using SmartProduction.Domain.yjh;
using SmartProduction.ErrorCode;
using SmartProduction.Infarstructrue.Interface;
using SmartProduction.Read.API.Application.Commands.MaterList;

namespace SmartProduction.Read.API.Application.CommandHandlers.MaterList
{
    /// <summary>
    /// 物料类型查询命令
    /// </summary>
    public class MaterListTypeQueryCommandHandler:IRequestHandler<MaterListTypeQueryCommad,APIResult<List<MaterialListType>>>
    {
        /// <summary>
        /// 物料类型仓储
        /// </summary>
        private readonly IBaseRepository<MaterialListType> mattypeRep;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="mattypeRep">物料类型仓储</param>
        public MaterListTypeQueryCommandHandler(IBaseRepository<MaterialListType> mattypeRep)
        {
            this.mattypeRep = mattypeRep;
        }
        /// <summary>
        /// 处理
        /// </summary>
        /// <param name="request">实体</param>
        /// <param name="cancellationToken">取消</param>
        /// <returns>返回任务</returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<APIResult<List<MaterialListType>>> Handle(MaterListTypeQueryCommad request, CancellationToken cancellationToken)
        {
           APIResult<List<MaterialListType>> result=new APIResult<List<MaterialListType>>();

            var list=mattypeRep.GetAll().Result;

            result.Code = APIEnums.查询成功;
            result.Msg = APIEnums.查询成功.ToString();
            result.data = list.ToList();


            return await Task.FromResult(result);
        }
    }
}
